<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ include file="/pages/login/common.jsp"%>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.商品分类设置</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/btn.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/proManage.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/themes.css" />
<link rel="stylesheet" href="<%=path%>/include/JQuery zTree v3.4/css/demo.css">
<link rel="stylesheet" href="<%=path%>/include/JQuery zTree v3.4/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/register_icss.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/sweetalert/sweetalert.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/page.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/mmt_trading.css" />

<script type="text/javascript" src="<%=path%>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.shop.manage.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.common.js"></script>
<script type="text/javascript" src="<%=path%>/include/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/sweetalert/sweetalert-dev.js"></script>

<style type="text/css">

<style type ="text /css">.table tr td {
	border-left: 1px solid #ddd;
	border-bottom: 1px solid #ddd;
	height: 33px;
}

#addPro a {
	color: black;
	margin-right: 10px;
}

#addPro a:hover {
	background-color: white;
}

#addPro button {
	<%-- background-color: white;
	padding: 0px 8px;
	height: 25px;
	text-align: center;
	font-size: 12px;
	color: #000;
	border: #C9C5C5 1px solid;
	cursor: pointer;
	margin: 0;
	background-image:
		url("<%=path%>/include/css/img/xuanpu_sort_zss.png");
	background-position: 0 -254px;
	background-repeat: repeat-x; --%>
	width:44px;
    height:24px;
    line-height:24px;   
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 0 -203px;
    border:0;
    cursor:pointer;
    font: 12px/1.5 arial,tahoma,\5b8b\4f53;
    margin: 0 0 0 5px;
    outline:none;
    background-image: url('<%=path%>/include/css/img/xs_bgx.png');
}


#treeDemo{
    width:95%;
}
#tbody td{
    border-bottom: 1px solid #ddd;
    border-right: 1px solid #ddd;
    padding: 0px 4px;
	line-height:44px;
}
.table tr th {
	border-right: 1px solid #ddd;
	border-top: 1px solid #ddd;
	font-size: 12px;
}

</style>
<script type="text/javascript">
	$(function(){
		zTree = $.fn.zTree.init($("#treeDemo"), treeSetting);
		var argsFromPageA = args();
		$("#productTypeCode").val(argsFromPageA.tId);
		$("#productTypeId").val(argsFromPageA.bId);
		
		$("#tbody").html("<td colspan='8' style='text-align:center;line-height:40px;border-right:0px;' >请选择类别</>");
		
		
	});
	
	var pagination;
	function _queryList(){
		var productTypeCode = $("#productTypeCode").val();
		var proName = $("#proName").val();
		var url = "<%=path%>/categoryProduct/queryProductList.do";
		var data = {
			categoryCode : $("#categoryCode").val(),
			productTypeCode : productTypeCode,
			proName:proName
		};
		pagination = _initPagination({'pageId':'pagination', 'url': url,'data': data, 'rows': 10, 'callback':_initDataList});
	}
	
	function _initDataList(data) {		
 		var d = data.rows;		
		var str = "";
		for(var i=0;i<d.length;i++){
			str += '<tr class="list_table_tr" style="border: 1px solid #ddd;">';
			str += '	<td  nowrap ><input  name="selAlone" onclick="_checkAll(this)" value="' + d[i].PRODUCT_ID + '" type="checkbox" ></td>';
			str += '	<td style="text-align: left; "> &nbsp;' + d[i].PRODUCT_NAME + '</td>';
			str += '	<td  nowrap>';
			str += '    	<div>';
			str += "        		<img src='"+d[i].PRODUCT_PIC+"' style='vertical-align:middle;' width='50' height='41.5' alt='' onerror='javascript:this.src=\"<%=path%>/download/error/nopicture.jpg\"' resizeimg='true'>";
			str += ' 		</div>';
			str +='</td>';
			if(d[i].UP_STATUS==1){
				str += '	<td  nowrap>上架</td>';
			}else{
				str += '	<td  nowrap >下架</td>';
			}
			
			if(d[i].UP_STATUS==1){
				str += '	<td  style="text-align:center;" nowrap>';
				str += 			d[i].UP_TIME;
				str += '	</td>';
			}else{
				str += '	<td  style="text-align:center;" nowrap>';
				str += 			d[i].DOWN_TIME;
				str += '	</td>';
			}
			str += '	<td  nowrap  style="text-align: right;">' + d[i].PRODUCT_SCORE + '&nbsp;</td>';
			str += '	<td  nowrap  style="text-align: right;border-right:0px;">' + d[i].PRODUCT_SUM_SCORE_AMOUNT + '&nbsp;</td>';			
			str += '</tr>';
		}
		
		$("#tbody").html(str);
		
		if(d.length>0){
			
		}else{
			
			$("#tbody").html("<td colspan='7' style='text-align:center;line-height:40px;border-right: 1px solid #e0e0e0;border-left: 1px solid #e0e0e0;' >没有该分类的商品数据</>");
		}
		_reHeight();
	 }
	
	function _selectAll(obj){
		var alones=document.getElementsByName("selAlone");
		if(obj.checked==true){
			for(var i=0;i<alones.length;i++){
				alones[i].checked=true;
			}
		}else{
			for(var i=0;i<alones.length;i++){
				alones[i].checked=false;
			}
		}
	}
	
	function _checkAll(obj){
		//alert(1);
		var all=document.getElementById("selAll");
		var alones=document.getElementsByName("selAlone");
		var isAll=true;
		for(var i=0;i<alones.length;i++){
			if(alones[i].checked==false){
				
				isAll=false;
				break;
			}
		}
		all.checked=isAll;
		
		
	}
	var params = function(args) {
		var p = [];
		for(var n in args)
			p.push(n + '=' + args[n]);
		return encodeURI('?' + p.join('&'));
	};
	
	var args = function(params) {
		var a = {};
		params = params || location.search;
		if(!params) return {};
		params = decodeURI(params);
		params.replace(/(?:^\?|&)([^=&]+)(?:\=)([^=&]+)(?=&|$)/g, function(m, k, v) {
			a[k] = v;
		});
		return a;
	};
	
	function _returnPage(){
		//alert($("#productTypeId").val());
		var tId=$("#productTypeCode").val();
		var data = {tId:tId,bId:$("#productTypeId").val()};
		window.location.href='<%=path%>/productForManager/toProductForManagerList.do'+params(data);
	};
	
	function _saveProduct(){
		var productIds="";
		$("input[name='selAlone']").each(function(index,item){
			if($(this).attr("checked")=="checked"){
				productIds+=$(this).val()+",";
			}
		});
		if(productIds==""){
			 parent.swal("请至少选择一种商品!");
			 return;
		}else{
			var productTypeCode = $("#productTypeCode").val();
			$.ajax({
				type:"post",
				url: "<%=path %>/productForManager/saveProductForManager.do",
				data:{productIds:productIds,productTypeCode:productTypeCode},
				dataType:"json",
				success:function(data){
					if(data.success){
						parent.swal("","添加成功","success");
						_queryList();
					}
				}
			});
		}
		
	}
	
	
</script>
</head>
<body  style="font-family: '微软雅黑';">
	<input type="hidden" id="categoryCode" name="categoryCode" value="">
	<input type="hidden" id="productTypeId" name="productTypeId" value="">
	<input type="hidden" id="productTypeCode" name="productTypeCode" value="">
	<div id="contentDiv" style="padding:4px; width:99%;">
		<div class="colnums-2-ab-b">
			<div class="toptil">待选商品</div>
			<div style="width:20%; float: left;">
			  <div style="height:400px;width:100%;overflow-x: hidden;overflow-y:auto;">
				<ul id="treeDemo" class="ztree"
					style="margin-top:0;background-color:#fff;border:1px #ccc solid;width:93%;overflow:auto;"></ul>
			  </div>
		   </div>
			<div class="list_table_bot1" style="border-top: 1px solid #e0e0e0;width:79.2%; float: right;">
				<div style="padding-left:10px;height: 40px;line-height: 40px;font-size:14px;border-right: 1px solid #e0e0e0;
					border-left: 1px solid #e0e0e0;"id="addPro">
					商品名称：<input id="proName" name="proName" placeholder="请输入商品名称" style="width: 140px;padding-left: 2px;" onkeyup="_queryList()" />	
					  <button type="button" class="cxx_btn" onclick="_queryList()" style="margin-top: -5px;">查询</button>
					  <button type="button" class="cxx_btn" onclick="_saveProduct()" style="margin-top: -5px;">添加</button>
					  <button type="button" class="cxx_btn" onclick="_returnPage()" style="margin-top: -5px;">返回</button>					
				</div>
				<div class="row-fluid dataTables_wrapper">
					<table id="listTable"
						class="table table-hover table-nomargin table-bordered usertable dataTable"
						style="width: 100%; border-spacing: 0;">
						<thead>
							<tr class="trBgd" style=" background-color: #eee;text-align: center; height: 31px; border-right: 1px solid #e0e0e0;border-left: 1px solid #e0e0e0;
								white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
								<th ><input id="selAll" name="selAll" type="checkbox" onclick="_selectAll(this)" class="chk"></th>
								<th >商品名称</th>
								<th >图片</th>
								<th >上架/下架</th>
								<th >上架/下架时间</th>
								<th >商品评分</th>
								<th style="border-right:0px;">商品评分次数</th>
							</tr>
						</thead>
						<tbody id="tbody" style="font-size: 13px">
						</tbody>
					</table>
					<div id="pagination"></div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
  	$(document).ready(function(){
		_reHeight();
	});
 	
	function _reHeight(){
		var main = $(window.parent.document).find("#rightFrame");
		var mainheight = $("#contentDiv").height();
		main.height(mainheight);
	}
  	var zTree = null;
	/* 
	 * 下拉树的设置 
	 */  
	var treeSetting = {  
	    view: {  
	        dblClickExpand: false  
	    },  
		data: {  
			simpleData: {  
			    enable: true,
			    rootPId: 0
			}  
		},
		async:{
			enable: true,//设置ztree是否开启异步加载模式
			showLine: true ,//设置是否显示连接线
			type: "post",//post方式请求数据
			url: getUrl,//数据请求url
			autoParam:["id","name"],//异步加载时需要自动提交父节点属性的参数
			otherParam:{"otherParam":"zTreeAsyncTest"},
			dataFilter: filter
		},
		callback: {
			onClick: onClick,//点击节点
			onAsyncError : zTreeOnAsyncError,//加载失败
			onAsyncSuccess: zTreeOnAsyncSuccess//加载完成
		}
	}; 
	function getUrl(treeId, treeNode){
		var url = "<%=path%>/categoryProduct/getTree.do";
		return url;
	}

	/* 
	 * 点击事件 
	 */
	function onClick(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		nodes = zTree.getSelectedNodes();
		treeNode = nodes[0];
		/* if(treeNode.isParent){//判断是否是父节点
			
		}else{ */
		//$("#treeDemo_1_a").css("background-color","white");
			//alert(treeNode.tId);
		$("#categoryCode").val(treeNode.id);
		//$("#categoryName").text(treeNode.name);
		_queryList();
		//}

	}

	//过滤函数  
	function filter(treeId, parentNode, childNodes) {
		if (!childNodes)
			return null;
		for (var i = 0, l = childNodes.length; i < l; i++) {
			//childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');  
		}
		return childNodes;
	}
	//加载完成
	var firstAsyncSuccessFlag = 0;
	function zTreeOnAsyncSuccess(event, treeId, msg) {
		if (firstAsyncSuccessFlag == 0) {
			try {
				//调用默认展开第一个结点
				var nodes = zTree.getNodes();
				zTree.expandNode(nodes[0], true);

				firstAsyncSuccessFlag = 1;

			} catch (err) {

			}
		}
		$("#treeDemo_1_a").click();

	}
	//加载失败提示  
	function zTreeOnAsyncError(event, treeId, treeNode, XMLHttpRequest,
			textStatus, errorThrown) {
		alert("加载错误：" + XMLHttpRequest);
	};
</script>
</html>
